﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using JY.Wpf.Core.Extensions;
using JY.Wpf.Core.Tools;
using JY.Wpf.Core.ViewModelBases;
using JY.Wpf.Test.Views.MVVMDemoViews;
using Newtonsoft.Json;
using SD.IOC.Core.Mediators;

namespace JY.Wpf.Test.ViewModels.MVVMDemoViewModels
{
    /// <summary>
    /// 表单测试
    /// </summary>
    [NotifyPropertyChanged]
    public class FormTestViewModel : ChildWindowViewModelBase
    {
        #region # 变量
        
        #endregion

        #region # 构造器
        /// <summary>
        /// 构造器
        /// </summary>
        public FormTestViewModel()
        {
            List<string> qualifieds = new List<string>() { "合格", "不合格" };
            this.FormItems = new ObservableCollection<FormItem>()
            {
                new FormItem("感官鉴定", FormValueType.单选, qualifieds),
                new FormItem("滋气味", FormValueType.单选, qualifieds),
                new FormItem("温度(℃)", FormValueType.数字),
                new FormItem("酸度(°T)",FormValueType.数字),
                new FormItem("酒精试验", FormValueType.单选, qualifieds)
            };
        }
        #endregion

        #region # 属性
        #region 值——object Value
        public ObservableCollection<FormItem> FormItems { get; set; }

        #endregion
        #endregion

        #region # Command方法

        public void Set()
        {
        }

        #endregion

        #region # 方法

        #endregion

        #region # 获取页面 —— object GetView(object context = null)
        /// <summary>
        /// 获取页面
        /// </summary>
        /// <param name="context">页面</param>
        /// <returns></returns>
        public override object GetView(object context = null)
        {
            return ResolveMediator.Resolve<FormTestView>();
        }
        #endregion
    }

    [NotifyPropertyChanged]
    public class FormItem : PropertyChangedBase
    {
        public FormItem(string name, FormValueType formValueType, List<string> values=null)
        {
            this.Name = name;
            this.Values = values;
            this.FormValueType = formValueType;
        }
        #region 名称
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        #endregion

        #region 值——object Value
        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; }
        #endregion

        /// <summary>
        /// 值集合
        /// </summary>
        [System.Xml.Serialization.XmlIgnore]
        [JsonIgnore]
        public List<string> Values { get; set; }

        /// <summary>
        /// 表单值类型
        /// </summary>
        [System.Xml.Serialization.XmlIgnore]
        [JsonIgnore]
        public FormValueType FormValueType { get; set; }
    }

    public enum FormValueType
    {
        文本,
        数字,
        下拉列表,
        单选,
        多选,
        日期,
        日期时间,
        时间
    }
}
